class LabelEditorPureCanvas_SplitTxtByMaxWidth {
    public SplitTxtByMaxWidth(this: LabelEditorPureCanvas, txt: string, maxWidth: number) {
        let returnTxtArray: string[] = [""];
        for (let i = 0; i < txt.length; i++) {
            returnTxtArray[returnTxtArray.length - 1] += txt[i];
            if (this.ctx.measureText(returnTxtArray[returnTxtArray.length - 1] + txt[i + 1]).width > maxWidth) {
                let leftTxt: string = txt.substring(i + 1);
                if (this.ctx.measureText(leftTxt).width < maxWidth) {
                    returnTxtArray.push(leftTxt);
                    break;
                } else {
                    returnTxtArray.push("");
                }
            }
        }
        /**如果最后一行字符串没有值，直接删除最后一行。------------------------------ */
        if (returnTxtArray[returnTxtArray.length - 1].length == 0) {
            returnTxtArray.pop();
        }
        return returnTxtArray;
    }
}